<?php

declare(strict_types=1);

namespace App\Exception\Handler;

use Hyperf\Validation\ValidationException;
use Hyperf\Validation\ValidationExceptionHandler;
use Psr\Http\Message\ResponseInterface;
use App\Core\Response;
use Hyperf\Di\Annotation\Inject;
use Throwable;

class AppValidationExceptionHandler extends ValidationExceptionHandler
{

    /**
     * @Inject
     * @var Response
     */

    protected $response;

    public function handle(Throwable $throwable, ResponseInterface $response)
    {
        $this->stopPropagation();
        /** @var \Hyperf\Validation\ValidationException $throwable */
        $body = $throwable->validator->errors()->first();
        return $this->response->error(415,$body);
    }
}